package com.micro.modual.async.completion.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * <h1>异步规则枚举</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020/5/6
 */
@Getter
@AllArgsConstructor
public enum CompletionRuleFlag {

    ASYNC_COUPON_CODE("001","优惠券编号规则"),
    ASYNC_DEFAULT_USER_INFO("002","默认用户信息补全"),
    ASYNC_REMOVE_GOODS_SKU("003","移除商品sku相关信息");

    /**
     * 异步规则编码
     */
    private String code;

    /**
     * 异步规则描述信息
     */
    private String description;

    public static CompletionRuleFlag of(String code){
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code +"not exists"));
    }
}
